public class Test28 {
    public int strStr(String haystack, String needle) {
        char[] a=haystack.toCharArray();
        char[] b = needle.toCharArray();

        for (int i=0;i<a.length;i++){
            if (a[i]==b[0]){
                if (i+b.length>a.length){
                    break;
                }
                String substring = haystack.substring(i, i + b.length);
                if (substring.equals(needle)){
                    return i;
                }
            }
        }

        return -1;
    }
}
